﻿using EFModel;
using IServices;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;
using Y2.Dao;

namespace Serives
{
    [Obsolete]
    public class Teconfig_file_first_kind : Iconfig_file_first_kind
    {
        private readonly MyDBContext he;

        public Teconfig_file_first_kind(MyDBContext he)
        {
            this.he = he;
        }

        Task<ResultInfo> Iconfig_file_first_kind.Index3(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.config_file_first_kind;
                var list = he.config_file_first_kind
                    .Select(e => new { e.ffk_id, e.first_kind_id, e.first_kind_name, e.first_kind_salary_id, e.first_kind_sale_id })
                    .OrderBy(q => q.ffk_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }

        Task<int> Iconfig_file_first_kind.Updat(string first_kind_id, string first_kind_name, string first_kind_salary_id, string first_kind_sale_id, int ffk_id)
        {
            return Task.Run(() => {
                string sql = $@"update [dbo].[config_file_first_kind] set [first_kind_id]='{first_kind_id}',[first_kind_name]='{first_kind_name}',[first_kind_salary_id]='{first_kind_salary_id}',[first_kind_sale_id]='{first_kind_sale_id}'
                                                where [ffk_id]={ffk_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<int> Iconfig_file_first_kind.delt(int ffk_id)
        {
            return Task.Run(() => {
                string sql = $@"delete from [dbo].[config_file_first_kind]
                            where [ffk_id]={ffk_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<int> Iconfig_file_first_kind.Inser(string first_kind_id, string first_kind_name, string first_kind_salary_id, string first_kind_sale_id)
        { 
            return Task.Run(() => {
                string sql = $@"insert into [dbo].[config_file_first_kind]([first_kind_id], [first_kind_name], [first_kind_salary_id], [first_kind_sale_id])
                                values('{first_kind_id}','{first_kind_name}','{first_kind_salary_id}','{first_kind_sale_id}');";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

    }
}
